/* js library for popup effects */

(function(global) {
    var popup = popup || {};

    var WAITING = 2000;

    var showoff = false;

    popup.create = function() {
      if (!showoff) {
        var container = document.getElementById('container');
        $('#popup').html('<img src="/static/img/loading.gif" />');
        var containerWidth = container.clientWidth,
            containerHeight = container.clientHeight,
            imgWidth = $('#popup > img').width();

        $('#popup').css({'position': 'absolute', 'width':'240px','height':'50px', 'left':'50%','top':'400px','margin-left':'-120px','opacity':'0.8'});
        //$('#popup').css({'height':containerHeight});
        //$('#popup').css({'width': containerWidth});

        //$('#popup > img').css({'position': 'absolute', 'top':'40%', 'left':'45%'});
        $('#popup').fadeIn(100);
        showoff = true;
      }
    };

    popup.disable = function(message) {
      if (showoff) {
        $('#popup').html('<h3>'+message+'</h3>');
        $('#popup > h3').css({'position': 'relative', 'top':'0px', 'left':'3%'}); 
        setTimeout(function() {
            $('#popup').fadeOut('slow');
            showoff = false;
          }, WAITING);
      }
    };

    popup.remove = function(message) {
      if (showoff) {
        $('#popup').html('<h3>'+message+'</h3>');
        $('#popup > h3').css({'position': 'relative', 'top':'0px', 'left':'3%'}); 
        setTimeout(function() {
            $('#popup').fadeOut('slow');
            showoff = false;
          }, WAITING);
      }
    };                                  

    popup.center = function(element) {
      var elementWidth = element.clientWidth,
          elementHeight = element.clientHeight,
          popupHeight = $('#popup').height(),
          popupWidth = $('#popup').width(),
          imgWidth = $('#popup > img').width();

      $('#popup').css({'height':elementHeight});
    };

    global.popup = popup;

})(window);
